{include file='../common_admin/left_bar.php'}
<link href="{$CSSDIR}/emoji.css?cb={time()}" rel="stylesheet" type="text/css" />
<link href="http://cdn.bootcss.com/jqueryui/1.12.0/jquery-ui.min.css" rel="stylesheet">
<style>
    .file{
        width: 160px;
    }

    table tr{
        height: 15px;
    }

    form table tr td{
        width: 100px;
    }
</style>
<form method="post">
    <div style="padding: 10px;" class="tixian-container" >
        <input type="hidden" name="urls" id="urls" value="{$base_url}&a=add_game">
        <input type="hidden" name="id" id="id" value="">
        <table>

            </tr>
            <tr id="news">
                <td>经典游戏名称:</td>
                <td><input type="text" name="gamename"></td>
                <td></td>
                <td style="width: 60px">去玩路径</td>
                <td><input type="text" name="path"></td>
                <td></td>
               
            </tr>
            <tr></tr>
            <tr>
                <td>消耗金币:</td>
                <td><input type="number" name="usedgold"></td>
                <td></td>
                <td>游戏图片</td>
                <td>
                    <input type="text" name="gameimg" value="{$xiaochengxu_editor['img_card']}"><br>
                    <input type="file" name="gameimgfile" class="file" onchange="changes(this)" id="gameimgfile">
                </td>
            </tr>
            <tr></tr>
            <tr>
                <td>备注:</td>
                <td>
                    <textarea cols="50" rows="5" name="remark"></textarea>
                </td>
            </tr>
            <tr>

            </tr>
            <tr>
                <td><input type="button" value="新建/修改" class="btn" onclick="news()"></td>
            </tr>
        </table>
    </div>
</form>
<div style="padding: 10px;">
    <table class='table table-striped'>
        <thead>
        <th style="width:100px">游戏ID</th>
       <th style="width:200px">游戏名称</th>
       <th style="width:200px;text-align: center">玩该游戏消耗金币</th>
        <th style="width:200px">游戏图片</th>
        <th style="width: 230px">创建时间</th>
        <th style="width:200px;text-align: center;" colspan="2">操作</th>
        </thead>
        <tbody>
        <!--{foreach from=$game_info item=v}-->
        <tr style="border-bottom: solid 1px #cccccc;">
           <td>{$v.id}</td>
            <td>{$v.gamename}</td>
            <td style="text-align: center">{$v.usedgold}</td>
            <td><img src="{$v.gameimg}" alt="" style="width: 100px;height: 100px"></td>
         <td>{date("Y-m-d H:i",$v['createtime'])}</td>
            <td  style="text-align: center"><input type="button" value="修改" class="btn" onclick="editor({$v.id})"></td>
        </tr>
        <!--{/foreach}-->
        </tbody>

    </table>
</div>



<div>
    <div style="padding: 10px; background-color: #f3f3f3;">共 <span style="color: #4E8DE5;">{$total_count}</span> 条 <span
            style="margin-left: 10px;">第 <span style="color: #4E8DE5;">{$page}</span> 页/共 <span
                style="color: #4E8DE5;">{$total_page}</span> 页</span> <a style="margin-left: 10px; color: #4E8DE5;"
                                                                         href="{$page_url}&page=1">首页</a> {if
        $page==1}<span style="margin-left: 10px;">上一页</span>{else}<a style="margin-left: 10px; color: #4E8DE5;"
                                                                     href="{$page_url}&page={$page-1}">上一页</a>{/if} {if
        $page==$total_page}<span style="margin-left: 10px;">下一页</span>{else}<a
            style="margin-left: 10px; color: #4E8DE5;" href="{$page_url}&page={$page+1}">下一页</a>{/if} <a
            style="margin-left: 10px; color: #4E8DE5;" href="{$page_url}&page={$total_page}">尾页</a>
        <span style="margin-left: 10px;">请选择页码：</span>
        <select id="selectPageTop" style="margin-left: 10px" onchange="change_page('top')">
            <option>请选择页码</option>
            <!--  {foreach from=$page_nums item=v key=k} -->
            <option value="{$v}" {if $v== $page}selected="selected" {/if}>{$v}</option>
            <!--  {/foreach} -->
        </select>
    </div>
</div>

<script src="http://cdn.bootcss.com/jqueryui/1.12.0/jquery-ui.min.js"></script>
<script src="{$JSDIR}/evol-colorpicker.min.js" type="text/javascript"></script>
<script>window.jQuery || document.write('<script src="{$JSDIR}/jquery-1.11.0.min.js"><\/script>')</script>
<script type="text/javascript">

    function news() {
        gamename = $.trim($(":input[name='gamename']").val());
         path = $.trim($(":input[name='path']").val());
        usedgold = $.trim($(":input[name='usedgold']").val());
        gameimg = $.trim($(":input[name='gameimg']").val());
        remark = $.trim($(":input[name='remark']").val());
        if (gamename.length == 0 || path.length == 0 || usedgold.length == 0 || gameimg.length == 0 || remark.length == 0) {
            alert("输入框不能为空");
            return;
        }
        urls=$("#urls").val();
        id=$("#id").val();
        if(id!=0 && id.length>0){
            $.ajax({
                url: urls,
                data: {
                    'id':id,
                    'gamename': gamename,
                    'path': path,
                    'usedgold': usedgold,
                    'gameimg': gameimg,
                    'remark': remark
                },
                type: 'post',
                dataType: 'json',

                success: function (data) {},

                error: function (data) {}
            });
        }else{
            $.ajax({
                url: urls,
                data: {
                    'gamename': gamename,
                    'path': path,
                    'usedgold': usedgold,
                    'gameimg': gameimg,
                    'remark': remark
                },
                type: 'post',
                dataType: 'json',


                success: function (data) {},

                error: function (data) {}
            });
        }


        gameimgfile=$("#gameimgfile").val();
        if(gameimgfile.length>0){
            var gameimgfile=new FormData();
            var gameimgObj=document.getElementById("gameimgfile").files[0];
            gameimgfile.append("file",gameimgObj);
            var xhr = new XMLHttpRequest();
            var FileController=urls;
            xhr.open("post", FileController, true);
            xhr.send(gameimgfile);
        }
        alert('操作成功');
        location.href = "{$base_url}&a=main";
    }

    function  changes(obj){
        fileurl=$(obj).val();
        $(":input[name='gameimg']").val(fileurl);
    }

    function editor(obj) {
        $(":input[name='channel']").attr('readonly',"true");
        $(":input[name='urls']").val("{$base_url}&a=editor");
        id=obj;
        $(":input[name='id']").val(id);
        $.ajax({
            url: "{$base_url}&a=find",
            data: {
                'id':id
            },
            type: 'post',
            dataType: 'json',

            success: function (data) {
                result=data.result;
                $(":input[name='gamename']").val(result.gamename);
                $(":input[name='path']").val(result.path);
                $(":input[name='usedgold']").val(result.usedgold);
                $(":input[name='gameimg']").val(result.gameimg);
                $(":input[name='remark']").val(result.remark);

            },

            error: function (data) {}
        });
    }

    function change_page(pos) {
        var objS;
        if ('top' == pos) {
            objS = document.getElementById("selectPageTop");
        } else if ('bot' == pos) {
            objS = document.getElementById("selectPageBot");
        }

        var selectedPage = objS.options[objS.selectedIndex].value;
        location.href = "{$page_url}&page=" + selectedPage;
    }
</script>
{include file='../common_admin/right_bar.php'}